home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 36 / pc_ipc.zip / RX_PROC.C < prev    next >
Text File  |  1989-11-17  |  3KB  |  94 lines

  1. /****************************************************************/
  2. /*                                */
  3. /*     RX_PROC.C : A demonstration of IPC usage for a        */
  4. /*            Receiving process                */
  5. /*                                */
  6. /*   Copyrighted (c) 1989 Donnelly Software Engineering.    */
  7. /*                                */
  8. /*    Refer to the comment block in TX_PROC.C for examples    */
  9. /*    illustrating compiling and linking.            */
  10. /*                                */
  11. /****************************************************************/
  12.  
  13.  
  14. #include <stdio.h>        /* standard i/o routines */
  15. #include "pc-ipc.h"        /* contains defines and typedef */
  16.  
  17. main()                /* start of main program */
  18. {
  19.  
  20.     char my_data[128];        /* a 128-byte data buffer */
  21.     IPC_PARAM_BLOCK p_block;    /* a variable of type IPC_PARAM_BLOCK */
  22.     unsigned int proc_1_id = 0;    /* storage for process ids */
  23.     unsigned int proc_2_id;
  24.     unsigned int read_cmnd;    /* read and wait if DV running */
  25.  
  26.  
  27. /* determine if IPC is installed at the default vector */
  28.     if ( !pc_ipc_installed(IPC_VECTOR) )
  29.         ipc_error(IPC_ERR_NOTINST);
  30.  
  31. /* Is there is a message for process 0? If so, then TX_PROC has already run */
  32.     init_param_block(&p_block, proc_1_id, 0, IPC_CMND_INQUIRE, 0, 0L);
  33.     pc_ipc(IPC_VECTOR, &p_block);
  34.  
  35.     if (( !p_block.error ) && (p_block.status & IPC_STAT_AVDATA))
  36.         {
  37.         init_param_block(&p_block, proc_1_id, 0, IPC_CMND_RDATA, 0,
  38.                         (void far *)(&proc_2_id));
  39.         pc_ipc(IPC_VECTOR, &p_block);
  40.  
  41.         if ( p_block.error )
  42.         ipc_error(p_block.error);
  43.  
  44.         read_cmnd = IPC_CMND_RDATA;
  45.         }
  46.  
  47. /* No, get a second process id and send it to process 0 for TX_PROC to find */
  48.     else
  49.         {
  50.         init_param_block(&p_block, 0, 0, IPC_CMND_REQID, 0, 0L);
  51.         pc_ipc(IPC_VECTOR, &p_block);
  52.  
  53.         if ( p_block.error )    /* terminate if no ids left */
  54.         ipc_error(p_block.error);
  55.  
  56.         proc_2_id = p_block.my_id;
  57.                     /* send the new id to process 0 */
  58.         init_param_block(&p_block, proc_2_id, proc_1_id, IPC_CMND_SDATA,
  59.             sizeof(unsigned int), (void far *)(&proc_2_id));
  60.         pc_ipc(IPC_VECTOR, &p_block);
  61.  
  62.         if ( p_block.error )
  63.         ipc_error(p_block.error);
  64.  
  65.         read_cmnd = IPC_CMND_RDATAW;
  66.         }
  67.  
  68. /* Initialize the parameter block and retieve a message */
  69.     init_param_block (&p_block, proc_2_id, 0, read_cmnd, 0, &my_data);
  70.     pc_ipc(IPC_VECTOR, &p_block);
  71.  
  72.     if ( p_block.error )
  73.         ipc_error(p_block.error);
  74.  
  75. /* If a message was received, print it */
  76.     if (p_block.status && IPC_STAT_AVDATA)
  77.         {
  78.         printf("Process-%d received %d bytes of data from Process-%d\n",
  79.                 p_block.my_id, p_block.size, p_block.to_id);
  80.         printf("\"%s\"\n", p_block.data_ptr);
  81.         }
  82.  
  83.     else
  84.       printf("No data available for Process-%d\n", p_block.my_id);
  85.  
  86. /* relinquish the process id if one was allocated */
  87.     if (read_cmnd == IPC_CMND_RDATAW)
  88.         {
  89.         init_param_block(&p_block, proc_2_id, 0, IPC_CMND_DELID, 0, 0L);
  90.         pc_ipc(IPC_VECTOR, &p_block);
  91.         }
  92.  
  93. }    /* end of procedure main */
  94.